package com.commit.service.impl;

import com.commit.domain.Reply;
import com.commit.domain.User;
import com.commit.mapper.ReplyMapper;
import com.commit.ownException.NotFoundException;
import com.commit.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @author:zyh
 * @Time:2021-03-15-9:21
 * @email:1269231889@qq.com
 */
public class ReplyServiceImpl implements ReplyService {
    @Autowired
    private ReplyMapper replyMapper;

    @Override
    public String reply(String content, Integer answerId, HttpSession session) {
        User user = (User) session.getAttribute("user");
        if(user==null){
            return "login";
        }
        Reply reply = new Reply(answerId, content, user.getId(), new Date());
        replyMapper.insert(reply);
        return "success";
    }

    @Override
    public List<Reply> allReply(Integer answerId) {
        List<Reply> replies = replyMapper.allReply(answerId);
        if(replies==null){
            throw new NotFoundException("没有");
        }
        return replies;
    }
}
